package com.xoa.controller.easyReport;

import com.alibaba.fastjson.JSONObject;
import com.xoa.model.easyReport.RepReport;
import com.xoa.service.easyReport.RepDataService;
import com.xoa.service.easyReport.RepStatisticsService;
import com.xoa.util.ToJson;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.OutputStreamWriter;

/**
 * 创建人: liujian
 * 创建时间: 2020/2/5
 * 描述:填报数据统计分析
 */
@Controller
@RequestMapping("/repStatistics")
public class repStatisticsController {

    @Autowired
    RepStatisticsService repStatisticsService;

    @Autowired
    RepDataService repDataService;

    //通过临时表查询
    /**
     * 创建人: liujian
     * 创建时间: 2020/2/8
     * 参数: [type = 0 按照fieldStr升序排序 ,type = 1 按照fieldStr分组查询 ]
     */
    @ResponseBody
    @RequestMapping("/temDatasByTableId")
    public ToJson<RepReport> temDatasByTableId(String type,Integer fieldId ,Integer tableId,String userId, String startTime , String endTime,String groupBy ) {
        return repStatisticsService.temDatasByTableId(type,fieldId,tableId,userId,startTime,endTime,groupBy);
    }

    //通过临时表查询
    /**
     * 创建人: liujian
     * 创建时间: 2020/2/8
     * 参数: [type = 0 按照fieldStr升序排序 ,type = 1 按照fieldStr分组查询 ]
     */
    @ResponseBody
    @RequestMapping("/exportDatasByTableId")
    public ToJson<RepReport> exportDatasByTableId(HttpServletRequest request, HttpServletResponse response,String type, Integer fieldId , Integer tableId, String userId, String startTime , String endTime, String groupBy ) {
        return repStatisticsService.exportDatas(request,response,type,fieldId,tableId,userId,startTime,endTime,groupBy);
    }

    /**
     * 接口说明： 条件汇总（分组）
     * 创建人: 廉立深
     * 创建时间: 2020/2/8
     * @return type:状态需要进行什么操作
     */
    @RequestMapping("/findReportCondition")
    @ResponseBody
    public ToJson findReportCondition(HttpServletRequest request , String json){
        return repStatisticsService.findReportCondition(request,json);
    }



    /**
     * 查询第一个字段根据最小的字段排序号
     */
    @RequestMapping("/findminfield")
    @ResponseBody
    public ToJson findminfield(HttpServletRequest request , Integer tableId){
        return repStatisticsService.findminfield(request,tableId);
    }


    /**
     * 通用汇总导出
     * @param request
     * @return
     */
    @RequestMapping("/ExportReportCondition")
    @ResponseBody
    public ToJson ExportReportCondition(HttpServletRequest request, HttpServletResponse response , String tableId, String startTime, String endTime,boolean template,String flag){
        return repStatisticsService.ExportReportCondition(request,response,tableId,startTime,endTime,template,flag);
    }



    /**
     * 通用汇总导入
     * @param request
     * @return
     */
    @RequestMapping("/ImportReportCondition")
    @ResponseBody
    public ToJson ImportReportCondition(HttpServletRequest request,HttpServletResponse response, MultipartFile file, String json){
        return repStatisticsService.ImportReportCondition(request, file, json);
    }


}
